//
//  TBRRentController.m
//  TBRentClient
//
//  Created by tonbright on 2018/4/26.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRRentController.h"

#import "TBRBuinessRentAppointmentCell.h"
#import "TBRReceptPlaneAppointCell.h"
#import "TBRSendPlaneAppointCell.h"
#import "TBRCharterAppointCell.h"
#import "TBRSelfDriveAppointCell.h"

#import "TBRGetRentDetailMessageC.h"
#import "TBRHomeModel.h"

#import "TBRTextPickerC.h"
#import "TBRSelfDrivePickerC.h"
#import "TBROnCarPlaceC.h"
#import "TBRGetPlaneMessageC.h"

#import "LocationHelper.h"
#import "BRPickerView.h"
#import "YXDateHelpObject.h"
@interface TBRRentController ()<MenuViewDelegate,UITableViewDelegate,UITableViewDataSource,TBRBuinessRentAppointmentCellDelegate,TBRReceptPlaneAppointCellDelegate,TBRSendPlaneAppointCellDelegate,TBRCharterAppointCellDelegate,TBRSelfDriveAppointCellDelegate,ISGLocationHelperDelegate>

@property (nonatomic,strong)UITableView *tableView;
//@property (nonatomic,strong)TBREstimatePriceView *estimatePriceView;//预估价格的view-----

@property (nonatomic, strong) LocationHelper   *locationHelper;

@property (nonatomic,copy)NSString *locationCity;//定位城市
@property (nonatomic,copy)NSString *locationProvince;//定位省份
@property (nonatomic,copy)NSString *locationArea;//定位区域
@property (nonatomic,copy)NSString *currentCity;//当前选择城市  默认选择上海


// MARK: - 自驾的数据----------------------
@property (nonatomic,copy)NSString *timeDuration;//间隔时间----

@property (nonatomic,strong)NSArray *charterTimeDurationArray;
@property (nonatomic,strong)NSArray *airportArray;//机场数组
@property (nonatomic,strong)NSArray *onOffPlaceArray;//上下车位置数组-------
@end

@implementation TBRRentController

- (void)viewDidLoad {
    [super viewDidLoad];
    //开始定位--------
    [self startLocation];
    [self setupUI];
    [self loadData];
}

- (void)setupUI {
    //设置导航条
    self.titleText = @"尊行租车";
    [self ISG_NavigationBarLeftTitle:@"首页"];
    MenuView *titleMenuView = [[MenuView alloc] initWithMenuViewWithFrame:CGRectMake(10, 0, self.view.frame.size.width-20, 44) titles:@[@"商务接送",@"接机",@"送机",@"包车",@"自驾租车"] index:self.selectedIndex];
    self.titleMenuView = titleMenuView;
    titleMenuView.delegate = self;
    [self.view addSubview:titleMenuView];
    [self menuView:self.titleMenuView didSelectedIndex:_selectedIndex-1];
    
    [self setupTableView];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUI) name:KRent_detailBackBtnClick_Notice object:nil];
}

- (void)refreshUI {
    [self.tableView reloadData];
}


- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)setupTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [UIColor colorWithHex:0xe6e6e6];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(0);
        make.leading.offset(10);
        make.trailing.offset(-10);
        make.top.equalTo(self.titleMenuView.bottom).offset(0);
    }];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 260;
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRBuinessRentAppointmentCell" bundle:nil] forCellReuseIdentifier:@"TBRBuinessRentAppointmentCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRReceptPlaneAppointCell" bundle:nil] forCellReuseIdentifier:@"TBRReceptPlaneAppointCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRSendPlaneAppointCell" bundle:nil] forCellReuseIdentifier:@"TBRSendPlaneAppointCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRCharterAppointCell" bundle:nil] forCellReuseIdentifier:@"TBRCharterAppointCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRSelfDriveAppointCell" bundle:nil] forCellReuseIdentifier:@"TBRSelfDriveAppointCellId"];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 10)];
    }
    self.tableView.showsVerticalScrollIndicator = NO;
}

#pragma mark - 实现数据源方法
#pragma mark - 返回组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

#pragma mark - 返回行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

#pragma mark - 返回每行内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self getIdentifier:indexPath] forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (self.selectedIndex == 1) {
        TBRBuinessRentAppointmentCell *cellBuiness = (TBRBuinessRentAppointmentCell *)cell;
        [cellBuiness refreshUI];
        cellBuiness.delegate = self;
    }else if (self.selectedIndex == 2) {
        TBRReceptPlaneAppointCell *cellReceptPlane = (TBRReceptPlaneAppointCell *)cell;
        //显示的是飞机的位置---不能用一个变量保存-------------------
        [cellReceptPlane refreshUI];
        cellReceptPlane.delegate = self;
    }else if (self.selectedIndex == 3) {
        TBRSendPlaneAppointCell *cellSendPlane = (TBRSendPlaneAppointCell *)cell;
        [cellSendPlane refreshUI];
        cellSendPlane.delegate = self;
    }else if (self.selectedIndex == 4) {
        TBRCharterAppointCell *cellCharter = (TBRCharterAppointCell *)cell;
        [cellCharter refreshUI];
        cellCharter.delegate = self;
    }else if (self.selectedIndex == 5) {
        TBRSelfDriveAppointCell *cellSelfDrive = (TBRSelfDriveAppointCell *)cell;
        [cellSelfDrive refreshUI];
        self.timeDuration = [NSString stringWithFormat:@"%ld",[AppSetting shareAppSetting].timeDuration];
        cellSelfDrive.delegate = self;
    }
    return cell;
}

// MARK: - 商务接送
- (void)BuinessRentAppointmentCellBtnClick:(NSInteger)tag {
    if (tag == 10) {
        [self selBuinessRentAppointmentTimeBtnClick];
    }else if (tag == 20) {
        [self onOffCarPlaceBtnClick:YES];
    }else if (tag == 30) {
        [self onOffCarPlaceBtnClick:NO];
    }else if (tag == 40) {
        [self xuanChuanPicBtnClick];
    }
    
}

// MARK: - 接机
- (void)ReceptPlaneAppointCellBtnClick:(NSInteger)tag {
    if (tag == 10) {
        //输入航班号---
        TBRGetPlaneMessageC *getPlaneMessageC = [[TBRGetPlaneMessageC alloc] init];
        __weak typeof(self) weakSelf = self;
        getPlaneMessageC.getPlaneMessageCBlock = ^(TBRGetPlaneMessageModel *selPlaneModel) {
            //取出航班信息
            selPlaneModel.showPlaneStr = [NSString stringWithFormat:@"%@ %@到达%@航站楼%@",selPlaneModel.showselDateStr,selPlaneModel.planArriveTime,selPlaneModel.to,selPlaneModel.toTerminal];
            [TBRRentAllMessageModel shareAllMessageModel].selPlaneMessageModel = selPlaneModel;
            [weakSelf.tableView reloadData];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf jump2DetailAccordSelIndex:weakSelf.selectedIndex];
            });
        };
        
        [self.navigationController pushViewController:getPlaneMessageC animated:YES];
    }else if (tag == 20) {
        //下车地点
        [self onOffCarPlaceBtnClick:NO];
    }else if (tag == 30) {
        //图片点击
    }
}

// MARK: - 送机
- (void)sendPlaneAppointCellBtnClick:(NSInteger)tag {
    if (tag == 10) {
        [self selBuinessRentAppointmentTimeBtnClick];
    }else if (tag == 20) {
        [self onOffCarPlaceBtnClick:YES];
    }else if (tag == 30) {
//        [self onOffCarPlaceBtnClick:NO];
        [self selSendPlaneNum];
    }else if (tag == 40) {
        [self xuanChuanPicBtnClick];
    }
}

// MARK: - 包车
- (void)charterAppointCellBtnClick:(NSInteger)tag {
    if (tag == 10) {
        [self selBuinessRentAppointmentTimeBtnClick];
    }else if (tag == 20) {
        [self selTimeDuritonAndDistance];
    }else if (tag == 30) {
        [self onOffCarPlaceBtnClick:YES];
    }else if (tag == 40) {
        [self xuanChuanPicBtnClick];
    }
}

// MARK: - 自驾
- (void)selfDriveAppointCellBtnClick:(NSInteger)tag {
    TBRRentAllMessageModel *allMessageModel = [TBRRentAllMessageModel shareAllMessageModel];
    if (tag == 10) {
        [self selSelfDriveTimePicker:YES];
    }else if (tag == 20) {
        [self selSelfDriveTimePicker:NO];
    }else if (tag == 30) {
        //根据是否打开开关来选择-------
        if (allMessageModel.isGetCarFromShop) {
            [self selSelfDriveOnOffPlaceClick:YES];
            return;
        }
        [self onOffCarPlaceBtnClick:YES];
    }else if (tag == 40) {
        if (allMessageModel.isReBackCarToShop) {
            [self selSelfDriveOnOffPlaceClick:NO];
            return;
        }
        [self onOffCarPlaceBtnClick:NO];
    }
}

// MARK: - 包车时长选择---------
- (void)selTimeDuritonAndDistance {
    __weak typeof(self) weakSelf = self;
    TBRCharterAppointCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    __weak TBRCharterAppointCell *weakCellCharterAppointment = cell;
    [BRStringPickerView showStringPickerWithTitle:@"选择包车时长" dataSource:_charterTimeDurationArray defaultSelValue:weakCellCharterAppointment.lbe_timeDuration.text resultBlock:^(id selectValue) {
        weakCellCharterAppointment.lbe_timeDuration.text = selectValue;
        [TBRRentAllMessageModel shareAllMessageModel].charterTimeDuration = selectValue;
        [weakSelf jump2DetailAccordSelIndex:weakSelf.selectedIndex];
    }];
}


// MARK: - 商务接送 送机  包车 三种类型的 时间选择器
- (void)selBuinessRentAppointmentTimeBtnClick {
    //选择时间
    TBRTextPickerC *pickerC = [[TBRTextPickerC alloc] init];
    __weak TBRTextPickerC *weakPickerC = pickerC;
    __weak typeof(self) weakSelf = self;
    pickerC.pickerViewCancleBtnBlock = ^{
        [weakPickerC removeFromParentViewController];
        [weakPickerC.view removeFromSuperview];
    };
    pickerC.pickerViewSureBtnBlock = ^(NSString *dateStr, NSString *hourStr, NSString *minStr) {
        NSString *tmpDateStr = [dateStr componentsSeparatedByString:@" "].firstObject;
        tmpDateStr = [NSString stringWithFormat:@"%@ %@:%@",tmpDateStr,hourStr,minStr];
        [TBRRentAllMessageModel shareAllMessageModel].onCarTime = tmpDateStr;
        [weakSelf.tableView reloadData];
        [weakPickerC removeFromParentViewController];
        [weakPickerC.view removeFromSuperview];
    };
    [self.navigationController addChildViewController:pickerC];
    [self.navigationController.view addSubview:pickerC.view];
    pickerC.view.frame = [UIApplication sharedApplication].keyWindow.frame;
    pickerC.view.frame = CGRectMake(0, 0, Width, Height + 49);
}

// MARK: - 自驾类型的时间选择------------------------------
- (void)selSelfDriveTimePicker:(BOOL) isStartTime {
    TBRSelfDriveAppointCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    __weak typeof(self) weakSelf = self;
    __weak TBRSelfDriveAppointCell *weakCellSelfDriveAppoint = cell;
    TBRSelfDrivePickerC *pickerC = [[TBRSelfDrivePickerC alloc] init];
    pickerC.isStartTime = isStartTime;
    __weak TBRSelfDrivePickerC *weakPickerC = pickerC;
    pickerC.pickerViewCancleBtnBlock = ^{
        [weakPickerC removeFromParentViewController];
        [weakPickerC.view removeFromSuperview];
    };
    pickerC.pickerViewSureBtnBlock = ^(NSString *dateStr, NSString *hourStr, NSString *minStr,NSString *weekStr) {
        [weakPickerC removeFromParentViewController];
        [weakPickerC.view removeFromSuperview];
        NSString *startTimeStr = [TBRRentAllMessageModel shareAllMessageModel].startTime;
        NSString *endTimeStr = [TBRRentAllMessageModel shareAllMessageModel].endTime;
        NSDate *startDate = [[YXDateHelpObject manager] getDataFromStrFormat:@"yyyy/M/d H:m" String:startTimeStr];
        NSDate *endDate = [[YXDateHelpObject manager] getDataFromStrFormat:@"yyyy/M/d H:m" String:endTimeStr];
        

        NSInteger tmpDuration = [YXDateHelpObject numberOfDaysWithFromDate:startDate toDate:endDate];
        [AppSetting shareAppSetting].timeDuration = tmpDuration;
        weakSelf.timeDuration = [NSString stringWithFormat:@"%ld",[AppSetting shareAppSetting].timeDuration];
        [TBRRentAllMessageModel shareAllMessageModel].startDateTime = [[YXDateHelpObject manager] getCurentTime:@"M-dd" dateN:startDate];
        [TBRRentAllMessageModel shareAllMessageModel].endDateTime = [[YXDateHelpObject manager] getCurentTime:@"M-dd" dateN:endDate];
        
        if (isStartTime) {
            if (tmpDuration < 1) {
                [AppSetting shareAppSetting].timeDuration = 3;
                weakSelf.timeDuration = [NSString stringWithFormat:@"%ld",[AppSetting shareAppSetting].timeDuration];
                NSDate *newEndDate = [[YXDateHelpObject manager] getEarlyOrLaterDate:startDate LeadTime:3 Type:2];
                [TBRRentAllMessageModel shareAllMessageModel].endDateTime = [[YXDateHelpObject manager] getCurentTime:@"M-dd" dateN:newEndDate];
                
                [TBRRentAllMessageModel shareAllMessageModel].endWeakHour = [NSString stringWithFormat:@"%@ %@:%@",weekStr,hourStr,minStr];
                weakCellSelfDriveAppoint.lbe_endWeekHour.text = [TBRRentAllMessageModel shareAllMessageModel].endWeakHour;
                 weakCellSelfDriveAppoint.lbe_endDate.text = [TBRRentAllMessageModel shareAllMessageModel].endDateTime;
                [TBRRentAllMessageModel shareAllMessageModel].endTime = [[YXDateHelpObject manager] getCurentTime:@"yyyy/MM/dd H:mm" dateN:newEndDate];
            }
            
            [TBRRentAllMessageModel shareAllMessageModel].startWeakHour = [NSString stringWithFormat:@"%@ %@:%@",weekStr,hourStr,minStr];
            weakCellSelfDriveAppoint.lbe_StartWeekHour.text = [TBRRentAllMessageModel shareAllMessageModel].startWeakHour;
            weakCellSelfDriveAppoint.lbe_StartDate.text = [TBRRentAllMessageModel shareAllMessageModel].startDateTime;
        }else {
            [TBRRentAllMessageModel shareAllMessageModel].endWeakHour = [NSString stringWithFormat:@"%@ %@:%@",weekStr,hourStr,minStr];
            weakCellSelfDriveAppoint.lbe_endWeekHour.text = [TBRRentAllMessageModel shareAllMessageModel].endWeakHour;
            weakCellSelfDriveAppoint.lbe_endDate.text = [TBRRentAllMessageModel shareAllMessageModel].endDateTime;
        }
        weakCellSelfDriveAppoint.lbe_timeDuration.text = weakSelf.timeDuration;
    };
    [self.navigationController addChildViewController:pickerC];
    [self.navigationController.view addSubview:pickerC.view];
    pickerC.view.frame = [UIApplication sharedApplication].keyWindow.frame;
    pickerC.view.frame = CGRectMake(0, 0, Width, Height + 49);
}

// MARK: - 自驾后台数据位置选择---------
- (void)selSelfDriveOnOffPlaceClick:(BOOL)isGet {
    TBRSelfDriveAppointCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    __weak typeof(self) weakSelf = self;
    __weak TBRSelfDriveAppointCell *weakCellSelfDriveAppoint = cell;
    NSString *pointStrTmp = isGet ? @"请选择取车地点" : @"请选择还车地点";
    [BRStringPickerView showStringPickerWithTitle:pointStrTmp dataSource:self.onOffPlaceArray defaultSelValue:weakCellSelfDriveAppoint.lbe_offCarPlace.text resultBlock:^(id selectValue) {
        if (isGet) {
            weakCellSelfDriveAppoint.lbe_onCarPlace.text = selectValue;
            [TBRRentAllMessageModel shareAllMessageModel].isGetCarFromShopOnPlace = selectValue;
        }else {
            weakCellSelfDriveAppoint.lbe_offCarPlace.text = selectValue;
            [TBRRentAllMessageModel shareAllMessageModel].offPlace = selectValue;
        }
        [weakSelf jump2DetailAccordSelIndex:weakSelf.selectedIndex];
    }];
}

// MARK: - 自驾---定位位置选择------
- (void)onOffCarPlaceBtnClick:(BOOL)isOn {
    TBROnCarPlaceC *onCarPlaceC = [[TBROnCarPlaceC alloc] init];
    __weak typeof(self) weakSelf = self;
    onCarPlaceC.isOnCarPlace = isOn;
    onCarPlaceC.onCarPlaceBlock = ^(TBROnCarPlaceModel *carPlaceModel) {
        if (isOn) {
            [TBRRentAllMessageModel shareAllMessageModel].onPlace = carPlaceModel.titleStr;
        }else {
            [TBRRentAllMessageModel shareAllMessageModel].offPlace = carPlaceModel.titleStr;
        }
        [weakSelf.tableView reloadData];
        [weakSelf jump2DetailAccordSelIndex:weakSelf.selectedIndex];
        
    };
    onCarPlaceC.navigationItem.title = isOn ? @"请选择上车地点" : @"请选择下车地点";
    [[HelpObject getCurrentNav] pushViewController:onCarPlaceC animated:NO];
}

// MARK: - 选择航班
- (void)selSendPlaneNum {
    __weak typeof(self) weakSelf = self;
    TBRSendPlaneAppointCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    __weak TBRSendPlaneAppointCell *weakCellSendPlaneAppointment = cell;
    [BRStringPickerView showStringPickerWithTitle:@"请选择机场" dataSource:_airportArray defaultSelValue:weakCellSendPlaneAppointment.lbe_offCarPlace.text resultBlock:^(id selectValue) {
        weakCellSendPlaneAppointment.lbe_offCarPlace.text = selectValue;
        [TBRRentAllMessageModel shareAllMessageModel].toAirPort = selectValue;
        [weakSelf jump2DetailAccordSelIndex:weakSelf.selectedIndex];
    }];
}


// MARK: - 判断是否跳转的条件-----------
- (void)jump2DetailAccordSelIndex:(NSUInteger)index {
    TBRRentAllMessageModel *allMessageModel = [TBRRentAllMessageModel shareAllMessageModel];
    if (self.selectedIndex == 1) {
        if (![HelpObject isBlankString:allMessageModel.onPlace] && ![HelpObject isBlankString:allMessageModel.offPlace]) {
            [self jump2RentDetailC];
        }
    }
    
    else if (self.selectedIndex == 2) {
        if (![HelpObject isBlankString:allMessageModel.selPlaneMessageModel.showPlaneStr] && ![HelpObject isBlankString:allMessageModel.offPlace]) {
            [self jump2RentDetailC];
        }
    }
    else if (self.selectedIndex == 3) {
        if (![HelpObject isBlankString:allMessageModel.onPlace] && ![HelpObject isBlankString:allMessageModel.toAirPort]) {
            [self jump2RentDetailC];
        }
    }
    else if (self.selectedIndex == 4) {
        if (![HelpObject isBlankString:allMessageModel.onPlace] && ![HelpObject isBlankString:allMessageModel.charterTimeDuration]) {
            [self jump2RentDetailC];
        }
    }
    
    else if (self.selectedIndex == 5) {
        if (allMessageModel.isGetCarFromShop) {
            if (![HelpObject isBlankString:allMessageModel.isGetCarFromShopOnPlace] && ![HelpObject isBlankString:allMessageModel.offPlace]) {
                [self jump2RentDetailC];
            }
        }
        else {
            if (![HelpObject isBlankString:allMessageModel.onPlace] && ![HelpObject isBlankString:allMessageModel.offPlace]) {
                [self jump2RentDetailC];
            }
        }
    }
}

// MARK: - 跳转到订单详情页面----------
- (void)jump2RentDetailC {
    //调到其他控制器去了
    TBRGetRentDetailMessageC *businessRentDetailCViewController = [[TBRGetRentDetailMessageC alloc] init];
    businessRentDetailCViewController.selIndex = self.selectedIndex;
    businessRentDetailCViewController.onOffPlaceArray = self.onOffPlaceArray;
    __weak typeof(self) weakSelf = self;
    businessRentDetailCViewController.getRentDetailMessageCBlock = ^{
        [weakSelf.tableView reloadData];
    };
    [[HelpObject getCurrentNav] pushViewController:businessRentDetailCViewController animated:NO];
}


- (void)xuanChuanPicBtnClick {
    
}

// MARK: - 切换订车类型---顶部几个选项卡点击事件
- (void)menuView:(MenuView *)menuView didSelectedIndex:(NSInteger)index {
    self.selectedIndex = index + 1;
    [[TBRRentAllMessageModel shareAllMessageModel] resetRentMessage];
    [self.tableView reloadData];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self jump2DetailAccordSelIndex:self.selectedIndex];
    });
}


// MARK: - 写法有问题后续优化吧..
- (NSString *)getIdentifier:(NSIndexPath *)indexPath {
    NSString *iden = @"TBRBuinessRentAppointmentCellId";
    if (self.selectedIndex == 1) {
        iden = @"TBRBuinessRentAppointmentCellId";
    }else if (self.selectedIndex == 2) {
        iden = @"TBRReceptPlaneAppointCellId";
    }else if (self.selectedIndex == 3) {
        iden = @"TBRSendPlaneAppointCellId";
    }else if (self.selectedIndex == 4) {
        iden = @"TBRCharterAppointCellId";
    }else if (self.selectedIndex == 5) {
        iden = @"TBRSelfDriveAppointCellId";
    }
    return iden;
}

- (void)startLocation {
    _locationHelper = [[LocationHelper alloc] init];
    _locationHelper.delegate = self;
    [_locationHelper startLocation];
}
#pragma mark -ISGLocationHelperDelegate
- (void)locationHelper:(LocationHelper *)helper successWithModel:(ISGLocationInfoModel *)model {
    NSString *province = model.province;
    NSString *city = model.city;
    if ([province containsString:@"市"]) {
        //四大直辖市的城市信息无法通过locality获得，只能通过获取省份的方法来获得（如果city为空，则可知为直辖市）
        province = [province stringByReplacingOccurrencesOfString:@"市" withString:@""];
    }
    _locationCity = city;
    _locationProvince = province;
    _locationArea = model.area;
    [TBRRentAllMessageModel shareAllMessageModel].onPlace = model.sematicDescription;
    [self.tableView reloadData];
    [_locationHelper stopLocation];
}


// MARK: - 加载数据
- (void)loadData {
    [self loadLocalData];
    [self loadNetData];
}
// MARK: - 本地数据
- (void)loadLocalData {
    //自驾默认选择和间隔
    [AppSetting shareAppSetting].selStartIndex = 6;
    [AppSetting shareAppSetting].timeDuration = 3;
    NSDate *startDate = [[YXDateHelpObject manager] getEarlyOrLaterDate:[NSDate date] LeadTime:7 Type:2];
    NSDate *endDate = [[YXDateHelpObject manager] getEarlyOrLaterDate:[NSDate date] LeadTime:10 Type:2];
    NSString *tmpStartStr = [[YXDateHelpObject manager] getStrFromDateFormat:@"yyyy/MM/dd " Date:startDate];
    NSString *tmpEndStr = [[YXDateHelpObject manager] getStrFromDateFormat:@"yyyy/MM/dd " Date:endDate];
    [TBRRentAllMessageModel shareAllMessageModel].startTime = [NSString stringWithFormat:@"%@%@",tmpStartStr,@"8:00"];
    [TBRRentAllMessageModel shareAllMessageModel].endTime = [NSString stringWithFormat:@"%@%@",tmpEndStr,@"8:00"];
    
    NSString *startWeekStr = [[YXDateHelpObject manager] getBaseWeekly:startDate];
    NSString *endWeekStr = [[YXDateHelpObject manager] getBaseWeekly:endDate];
    [TBRRentAllMessageModel shareAllMessageModel].startDateTime = [[YXDateHelpObject manager] getCurentTime:@"M-dd" dateN:startDate];
    [TBRRentAllMessageModel shareAllMessageModel].endDateTime = [[YXDateHelpObject manager] getCurentTime:@"M-dd" dateN:endDate];
    self.timeDuration = [NSString stringWithFormat:@"%ld",[AppSetting shareAppSetting].timeDuration];
    [TBRRentAllMessageModel shareAllMessageModel].startWeakHour = [NSString stringWithFormat:@"%@ %@",startWeekStr,@"8:00"];
    [TBRRentAllMessageModel shareAllMessageModel].endWeakHour = [NSString stringWithFormat:@"%@ %@",endWeekStr,@"8:00"];
    
    //商务出行初始数据显示---------------------------------------------------------
    self.charterTimeDurationArray = @[@"4小时(包含50km)", @"8小时(包括100km)"];
    self.airportArray = @[@"浦东机场1号航站楼",@"浦东机场2号航站楼",@"浦东机场",@"虹桥机场1号航站楼",@"虹桥机场2号航站楼",@"虹桥机场"];
    self.onOffPlaceArray = @[@"龙华中路地铁站",@"浦东机场",@"上海交通大学",@"泗泾",@"虹桥机场2号航站楼",@"虹桥机场"];
//    [TBRRentAllMessageModel shareAllMessageModel].toAirPort = self.airportArray.firstObject;
//    [TBRRentAllMessageModel shareAllMessageModel].charterTimeDuration = self.charterTimeDurationArray.firstObject;
}

// MARK: - 获取网络数据-----
- (void)loadNetData {
    
}

@end
